// Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
// This source file is part of the Cangjie project, licensed under Apache-2.0
// with Runtime Library Exception.
//
// See https://cangjie-lang.cn/pages/LICENSE for license information.

#include "cangjie/AST/Match.h"

#ifndef CANGJIE_MIGRATOR_NODE_CAST
#define CANGJIE_MIGRATOR_NODE_CAST

namespace CangjieMigrator {

template <Cangjie::AST::ASTKind Kind, typename NodeT>
const auto &Cast(const NodeT &node)
{
    static_assert(std::is_base_of_v<Cangjie::AST::Node, NodeT>, "NodeT must be Node or a subclass of Node");
    static_assert(!std::is_pointer_v<NodeT>);
    return *Cangjie::AST::StaticAs<Kind>(&node);
}

template <Cangjie::AST::ASTKind Kind, typename NodeT>
const auto *Cast(const NodeT *node)
{
    static_assert(std::is_base_of_v<Cangjie::AST::Node, NodeT>, "NodeT must be Node or a subclass of Node");
    static_assert(!std::is_pointer_v<NodeT>);
    return Cangjie::AST::StaticAs<Kind>(node);
}

template <Cangjie::AST::ASTKind Kind, typename NodeT>
auto Cast(Ptr<NodeT> node)
{
    static_assert(std::is_base_of_v<Cangjie::AST::Node, NodeT>, "NodeT must be Node or a subclass of Node");
    return Cangjie::AST::StaticAs<Kind>(node);
}

} // namespace CangjieMigrator

#endif // CANGJIE_MIGRATOR_NODE_CAST
